<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@taglib uri="/webFormatUtil"  prefix="webFormatUtil"%>
	<c:if test="${empty requestScope.roomTypeList }">
			<center><h1>没有类型信息</h1></center>
	</c:if>
	<c:if test="${!empty requestScope.roomTypeList }">
		<!-- 资源管理模块 -->
		<div role="tabpanel" class="tab-pane active" id="sour">
			<div class="check-div form-inline">
				<button class="btn btn-yellow btn-xs" data-toggle="modal" data-target="#addDiv">添加房间类型</button>
			</div>
			<div class="data-div">
				<div class="row tableHeader">
					<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 ">
						类型名称
					</div>
					<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
						便利设施
					</div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
						最多人数
					</div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
						是否靠窗
					</div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
						房型基础价格
					</div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
						添加时间
					</div>
					<div class="col-lg-1 col-md-1 col-sm-1 col-xs-3">
						操作
					</div>
					</div>
					<div class="tablebody">
						<div id="collapseAccount" class="collapse in" aria-expanded="true">
							<c:forEach items="${requestScope.roomTypeList }" var="roomType">
								<div class="row">
									<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2 levl3 ">${roomType.name}
									</div>
									<div  class="col-lg-4 col-md-4 col-sm-4 col-xs-4 levl3 ">
									<button id="fac${roomType.id }" class="btn btn-success btn-xs" onclick="testLayer(${roomType.id },'${webFormatUtil:txtToHtml(roomType.facility) }')">查看</button>
									</div>
									<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl3 ">${roomType.num }
									</div>
									<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl3 ">${roomType.window?'√':' ' }
									</div>
									<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl3 ">${roomType.price }
									</div>
									<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 levl1 ">${roomType.addDate }
									</div>
									<div class="col-lg-1 col-md-1 col-sm-1 col-xs-3">
										<button class="btn btn-success btn-xs" data-toggle="modal" data-target="#addDiv"  onclick='changeButtonFun(${roomType.id})'>修改</button>
										<button class="btn btn-danger btn-xs" data-toggle="modal" data-target="" onclick='deleteButtonFun(${roomType.id})'>删除</button>
									</div>
								</div>
							</c:forEach>
						</div>
					</div>
				</div>
			</div>
	</c:if>
			<!--页码块-->
			<center>
				<a class="btn btn-xs btn-xs btn-green" onclick='jump("/hotel/roomType/roomTypeList?page=1")'>#首页
				</a>
				<a class="btn btn-xs btn-xs btn-green" onclick='jump("/hotel/roomType/roomTypeList?page=${currentPage==1?1:currentPage-1}")'>&lt;上一页
				</a>
				<a class="btn btn-xs btn-xs btn-green" onclick='jump("/hotel/roomType/roomTypeList?page=${currentPage+1}")'>下一页&gt;
				</a>
			</center>
	<!-- 添加房型菜单 -->
	<div class="modal fade" id="addDiv" role="dialog" aria-labelledby="gridSystemModalLabel">
    	<div class="modal-dialog" role="document">
			<input type="hidden" id="roomTypeId">
        	<div class="modal-content">
            	<div class="modal-header">
                	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    	<h4 class="modal-title" id="gridSystemModalLabel">添加房间类型</h4>
                </div>
                <div class="modal-body">
                	<div class="container-fluid">
                    	<div class="form-horizontal">
                        	<div class="form-group ">
                            	<label for="username" class="col-xs-3 control-label">类型名称：</label>
                                	<div class="col-xs-8 ">
                                    	<input type="text" class="form-control input-sm duiqi" id="name" placeholder="">
                                	</div>
                           </div>
		               		<div class="form-group">
		                    	<label for="facility" class="col-xs-3 control-label">便利设施:</label>
		                    	<div class="col-xs-8 ">
		                        	<textarea cols="15" rows="10" class="form-control input-sm duiqi" id="facility"></textarea><br>
		                   		</div>
		                    </div>
		                    <div class="form-group">
		                    	<label for="num" class="col-xs-3 control-label">最多人数:</label>
		                    	<div class="col-xs-8 ">
		                        	<input type="text" class="form-control input-sm duiqi" id="num" placeholder="">
		                   		</div>
		                    </div>
		                    <div class="form-group">
		                    	<label for="window" class="col-xs-3 control-label">是否靠窗：</label>
		                        <div class="col-xs-8">
		                        	<input id="window" type="checkbox" value="0"><br>
		                        </div>
		                    </div>
		                    <div class="form-group">
		                    	<label for="price" class="col-xs-3 control-label">基础价格:</label>
		                    	<div class="col-xs-8 ">
		                        	<input type="text" class="form-control input-sm duiqi" id="price" placeholder="">
		                   		</div>
		                    </div>
		                    <div class="form-group">
		                    	<label for="zcomment" class="col-xs-3 control-label">备注：</label>
		                        <div class="col-xs-8">
		                        	<textarea cols="15" rows="10" class="form-control input-sm duiqi" id="zcomment"></textarea><br>
		                        </div>
		                    </div>
               			 </div>
                      </div>
                  </div>
                  <div class="modal-footer">
                  	<button type="button" class="btn btn-xs btn-xs btn-white" data-dismiss="modal">取 消</button>
                  	<button type="button" class="btn btn-xs btn-xs btn-green" id="submit">提交</button>
                  	<button type="button" class="btn btn-xs btn-xs btn-green" id="change">修改</button>
				</div>
			</div>
		</div>
	</div>
	<style>
		#change{
			display:none;
		}
	</style>
	<script src="/hotel/js/layer.js"></script>
	<script src="/hotel/js/jumpUtil.js"></script>
	<script type="text/javascript">
		function testLayer(id,text){
			//小tips
			layer.tips(text, '#fac'+id, {
			  tips: [1, '#3595CC'],
			  time: 4000
			});
		}
		function clearContent(){
			$('#name').val('')
			$('#facility').text('');
			$('#num').val('')
			$("input[id='window']")[0].checked=false
			$('#price').val('')
			$('#discount').val('')
			$('#zcomment').text('');
		}
		$("#addButton").click(function(){
			$('#gridSystemModalLabel').text('添加房间类型')
			clearContent()
			var change=document.getElementById('change')
			change.style.display='none'
			var submit=document.getElementById('submit')
			submit.style.display='inline'
		})
		function changeButtonFun(id){
			//var add=document.getElementById('add')
			//add.style.display='block'
			$('#gridSystemModalLabel').text('修改房间类型')
			var change=document.getElementById('change')
			change.style.display='inline'
			var submit=document.getElementById('submit')
			submit.style.display='none'
			$.get("/hotel/roomType/getRoomTypeInfo?id="+id,{},function(res){
				//alert(res)
				var tn=eval('(' +res + ')').object
				//alert(tn.price)
				$('#roomTypeId').val(tn.id)
				$('#name').val(tn.name)
				$('#facility').text(tn.facility);
				$('#num').val(tn.num)
				windows=$("input[id='window']")[0]
				windows.checked=tn.window
				//alert($('#price').val())
				$('#price').val(tn.price)
				//$('#discount').val(tn.discount)
				$('#zcomment').text(tn.zcomment);
			})
		}
		function deleteButtonFun(id){
			if(confirm("您确定要删除该房间类型吗？")){
				$.post("/hotel/roomType/deleteRoomType.do",{"id":id},function(str){
					var res=eval('(' +str + ')')
					//alert(res.message);
					if(res.code==0){
						window.location.href="/hotel/system/mainPage"
					}else{
						alert(res.message);
					}
				});
			}
		}
		$("#submit").click(function(){
			windows=$("input[id='window']")[0].checked
			data={"name":$("#name").val(),"facility":$("#facility").val(),"num":$("#num").val(),
					"window":windows,"price":$("#price").val(),"discount":$("#discount").val(),"zcomment":$("#zcomment").val()
			}
			//alert(JSON.stringify(data))
			$.post("/hotel/roomType/addRoomType.do",data,function(str){
				var res=eval('(' +str + ')')
				//alert(res.message);
				if(res.code==0){
					//alert("成功？")
					window.location.href="/hotel/system/mainPage"
				}else{
					alert(res.message);
				}
			});
			return ;
		})
		$("#change").click(function(){
			windows=$("input[id='window']")[0].checked
			data={"id":$("#roomTypeId").val(),"name":$("#name").val(),"facility":$("#facility").val(),"num":$("#num").val(),
					"window":windows,"price":$("#price").val(),"discount":$("#discount").val(),"zcomment":$("#zcomment").val()
			}
			//alert(JSON.stringify(data))
			$.post("/hotel/roomType/changeRoomTypeInfo.do",data,function(str){
				var res=eval('(' +str + ')')
				//alert(res.message);
				if(res.code==0){
					window.location.href="/hotel/system/mainPage"
				}else{
					alert(res.message);
				}
			});
			return ;
		})
		$("#cancel").click(function(){
			var add=document.getElementById('add')
			add.style.display='none'
			clearContent()
		})
	</script>
</html>